<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 订单列表卡片 -->

    <el-card class="box-card">
      <el-input
        @clear="closeOrder"
        placeholder="请输入内容"
        v-model="Pagination.query"
        class="input-with-select"
        clearable
      >
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="getOrderList"
        ></el-button>
      </el-input>

      <template>
        <el-table :data="OrderList" border style="width: 100%">
          <el-table-column type="index" label="#"> </el-table-column>
          <el-table-column prop="order_number" label="订单编号" width="350">
          </el-table-column>
          <el-table-column prop="order_price" label="订单价格(元)">
          </el-table-column>
          <el-table-column prop="pay_status" label="是否付款">
          </el-table-column>
          <el-table-column prop="is_send" label="是否发货"> </el-table-column>

          <el-table-column label="下单时间">
            <template slot-scope="scope">
              {{ scope.row.create_time | FormData }}
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="primary"
                icon="el-icon-edit"
                @click="ediOrder(scope.row)"
              ></el-button>
              <el-button
                type="success"
                icon="el-icon-s-help"
                @click="showOrder(scope.row)"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- 修改订单loding框 -->
      <el-dialog
        title="修改订单信息"
        :visible.sync="ediOrderVisible"
        width="30%"
      >
        <el-form
          label-position="left"
          label-width="80px"
          :model="editOrderForm"
        >
          <el-form-item label="省市/区">
            <el-cascader
              v-model="editOrderForm.city"
              :options="options"
              :props="{ expandTrigger: 'hover' }"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址">
            <el-input v-model="editOrderForm.address"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="ediOrderVisible = false">取 消</el-button>
          <el-button type="primary" @click="ediOrderVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>

      <!-- 查看物流信息loading框 -->
      <el-dialog
        title="查看物流信息"
        :visible.sync="showOrderVisible"
        width="30%"
      >
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in showOrderList"
            :key="index"
            :timestamp="activity.time"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="showOrderVisible = false">取 消</el-button>
          <el-button type="primary" @click="showOrderVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>

      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="Pagination.pagenum"
        :page-sizes="[5, 6, 8, 10]"
        :page-size="Pagination.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="Pagination.total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import CityData from "./citydata.js";
export default {
  data() {
    return {
      options: CityData,
      showOrderList: [],
      OrderList: [],
      Pagination: {
        query: "",
        total: null,
        pagenum: 1,
        pagesize: 10,
      },
      ediOrderVisible: false,
      showOrderVisible: false,
      editOrderForm: {
        address: "",
        city: [],
      },
    };
  },
  filters: {
    FormData(val) {
      var date = new Date(val);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDay();

      return (date + "").substr(10, 14);
    },
  },
  mounted() {
    this.getOrderList();
  },
  methods: {
    // 获取订单列表数据
    async getOrderList() {
      // console.log(this.Pagination.query);
      const { data: res } = await this.$axios.get("orders", {
        params: {
          query: this.Pagination.query,
          pagenum: this.Pagination.pagenum,
          pagesize: this.Pagination.pagesize,
        },
      });
      this.Pagination.total = res.data.total;
      this.OrderList = res.data.goods;
      // console.log(res);
    },

    // 获取订单物流信息
    async getShowOders() {
      const { data: res } = await this.$axios.get("/kuaidi/1106975712662");
      this.showOrderList = res.data;
      console.log(res);
    },

    // 改变页码触发
    handleSizeChange(newpageseize) {
      this.Pagination.pagenum = 1;
      this.Pagination.pagesize = newpageseize;
      this.getOrderList();
    },

    // 改变页数触发
    handleCurrentChange(newpagenum) {
      this.Pagination.pagenum = newpagenum;
      this.getOrderList();
    },

    // 点击编辑订单信息
    ediOrder() {
      this.ediOrderVisible = true;
    },

    // 点击查看订单物流信息
    showOrder() {
      this.getShowOders();
      this.showOrderVisible = true;
    },

    // 点击清除订单搜索框
    closeOrder() {
      (this.Pagination.query = ""), this.getOrderList();
    },

    // 改变级联选择框触发
    handleChange(newval) {
      console.log(newval);
    },
  },
};
</script>

<style module></style>
